#include<stdio.h>
#include<stdlib.h>
#include"MyString.h"
#include<time.h>
#define Map_Size 5

struct DynamicArray
{
    void *dp;
    int size;
    int len;
};

struct Player
{
    int HP;
    int attack;
    int x;
    int y;
};

struct Monster
{
    MyString name;
    int HP;
    int attack;
    int x;
    int y;
};

struct Treasure
{
    MyString name;
    int value;
    int x;
    int y;
};

void InitPlayer(struct Player *player)
{
    player->HP=100;
    player->attack=10;
    player->x=0;
    player->y=0;
}

int GetRandNumber(int max)
{
    return rand()%max;
}

struct Monster* CreateMonster(const char *Name,int hp,int Attack)
{
    struct Monster *monster=(struct Monster *)malloc(sizeof(struct Monster));
    if(monster==NULL)
    {
        printf("Monster malloc error!\n");
        return NULL;
    }
    Initialize(&monster->name,Name);
    monster->HP=hp;
    monster->attack=Attack;

    monster->x=GetRandNumber(Map_Size);
    monster->y=GetRandNumber(Map_Size);

    return monster;
}

struct Treasure* CreateTreasure(const char *name,int value)
{
    struct Treasure *treasure=(struct Treasure*)malloc(sizeof(struct Treasure));
    if(treasure==NULL)
    {
        printf("Treasure malloc Error!\n");
        return NULL;
    }

    Initialize(&treasure->name,name);
    treasure->value=value;

    treasure->x=GetRandNumber(Map_Size);
    treasure->y=GetRandNumber(Map_Size);
}

void CreateDynamicArray(struct DynamicArray *array,int number)
{
    array->dp=malloc(sizeof(void*)*number);
    if(array->dp==NULL)
    {
        printf("DynamicArray malloc Error!\n");
        return NULL;
    }

    array->size=number;
    array->len=0;
}

int ReallocArray(struct DynamicArray *array)
{
    void*temp=array->dp;
    array->size=array->size*2;
    array->dp=(void *)malloc(sizeof(void)*array->size);
    if(array->dp==NULL)
    {
        printf("ReallocArray error!\n");
        array->dp=temp;
        array->size=array->size/2;
        return false;
    }

    for(int i=0;i<array->len;i++)
    {
        array->dp[i]=temp[i];
    }

    free(temp);
    return true;
}

void FreeArray(struct DynamicArray *array)
{
    if(array->dp!=NULL)
    {
        free(array->dp);
        array->dp=NULL;
        array->len=0;
    }
}

int main()
{

    return 0;
}